package com.kadron.common;

import java.io.Serializable;

import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.international.LocaleSelector;

import com.kadron.manager.KMessageManager;
import com.kadron.session.KUser;

@AutoCreate
@BypassInterceptors
@Name("kLangSelector")
@Scope(ScopeType.EVENT)
public class KLangSelector extends KMessageManager implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2659469685033354936L;

	public void select(String lang) {
		if (KUtil.isEmpty(lang)
				|| (!"EN".equals(lang) && !"ES".equals(lang) && !"SR".equals(lang))) {
			bad(KConst.BAD_THING);
			return;
		}
		try {
			LocaleSelector localeSelector = (LocaleSelector) Component.getInstance("org.jboss.seam.international.localeSelector",true);
//			FacesContext.getCurrentInstance().getViewRoot().setLocale(new Locale(lang));
			localeSelector.setLocaleString(lang);
			Contexts.getSessionContext().set("klang", lang);
			KUser kUser = (KUser) Component.getInstance("kUser");
			kUser.setKlang(lang);			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
